TrySetCanceled Method

Task Parallel System.Threading

Attempts to transition the underlying Task<(Of <(TResult>)>) into the Canceled state.

Namespace:  System.Threading.Tasks
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Function TrySetCanceled As Boolean
C#
public bool TrySetCanceled()

Return Value

True if the operation was successful; otherwise, false.

Remarks

This operation will return false if the Task<(Of <(TResult>)>) is already in one of the three final states: RanToCompletion, Faulted, or Canceled.

Exceptions

ExceptionCondition
System..::.ObjectDisposedExceptionThe Task was disposed.

See Also